package com.cutePet.pet.controller.wx;

import com.cutePet.common.utils.PageUtils;
import com.cutePet.common.utils.Query;
import com.cutePet.common.utils.R;
import com.cutePet.pet.domain.PetUserDO;
import com.cutePet.pet.service.PetUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 
 * 
 * @author charley
 * @email www.linqiaoli.com@qq.com
 * @date 2019-09-18 16:53:06
 */
 
@Controller
@RequestMapping("/wxPet/user")
public class WxPetUserController {
	@Autowired
	private PetUserService userService;

	@ResponseBody
	@GetMapping("/list")
	public PageUtils list(@RequestParam Map<String, Object> params){
		params.put("limit","10");
		params.put("offset","0");
		//查询列表数据
        Query query = new Query(params);
		List<PetUserDO> userList = userService.list(query);
		int total = userService.count(query);
		PageUtils pageUtils = new PageUtils(userList, total);
		return pageUtils;
	}
	
	/**
	 * 保存
	 */
	@ResponseBody
	@PostMapping("/save")
	public R save( PetUserDO user){
		if(userService.save(user)>0){
			return R.ok();
		}
		return R.error();
	}

	/**
	 * 修改
	 */
	@ResponseBody
	@RequestMapping("/update")
	public R update( PetUserDO user){
		userService.update(user);
		return R.ok();
	}
	
	/**
	 * 删除
	 */
	@PostMapping( "/remove")
	@ResponseBody
	public R remove( Long userId){
		if(userService.remove(userId)>0){
		return R.ok();
		}
		return R.error();
	}
	
	/**
	 * 删除
	 */
	@PostMapping( "/batchRemove")
	@ResponseBody
	public R remove(@RequestParam("ids[]") Long[] userIds){
		userService.batchRemove(userIds);
		return R.ok();
	}
	
}
